﻿<link href="~/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.css" rel="stylesheet" />
<script src="~/Scripts/jquery-easyui-extensions/menu/jeasyui.extensions.menu.js"></script>
<script src="~/Scripts/jquery-easyui-extensions/datagrid/jeasyui.extensions.datagrid.columnToggle.js"></script>

<div class="easyui-panel" data-options="fit:true,border:false,title:'列显示和隐藏'">
    <div id="toolbar1" style="padding:10px;">
        该 datagrid 控件已经开启显示 表头右键菜单 和 表头点击菜单，菜单中会提供“显示/隐藏/过滤列”的功能。
    </div>
    <table id="dg1"></table>
</div>

<script>
    $(function () {

        var getFrozenColumns = function () {
            var result = [];

            var c1 = [];
            c1.push({ field: 'ID', title: '主键', width: 100 });
            c1.push({ field: 'AreaName', title: '地区', width: 150,filterable: false });
            c1.push({ field: 'Sex1', title: '男', width: 90, sortable: true });
            c1.push({ field: 'Sex2', title: '女', width: 90 });

            result.push(c1);

            return result;
        };

        var getColumns = function () {
            var result = [];

            var normal00000 = [
                { field: 'TS1', title: '测试1', width: 80, hidable: false },
                { field: 'TS2', title: '测试2', width: 80, sortable: true },
                { field: 'TS3', title: '测试3', width: 120, hidable: true, formatter: function () { return "formatter出来的"; }, ignoreFormatterWhenFilter: true },
                { field: 'TS4', title: '测试4', width: 80, hidden: true }
            ];
            result.push(normal00000);

            return result;
        };
        var options = {
            idField: "ID",
            rownumbers: true,
            remoteSort: false,
            fit: true,
            border: false,
            singleSelect: true,
            toolbar: "#toolbar1",
            frozenColumns: getFrozenColumns(),
            columns: getColumns(),
            method: "get",
            url: "/Jsons/datagrid/datagrid-common-data.json",
            enableHeaderContextMenu: true,
            enableHeaderClickMenu: true
        };

        $("#dg1").datagrid(options);
    });
</script>